// Decompiled by DJ v3.9.9.91 Copyright 2005 Atanas Neshkov  Date: 2008-9-8 20:38:51
// Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   t_role_Manager.java

package com.creawor.hz_market.t_info_level;

import com.creawor.imei.base.BaseAction;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Session;
import org.apache.struts.action.*;

// Referenced classes of package com.creawor.hz_market.t_role:
//            t_role_QueryMap, t_role_Form, t_role_EditMap

public class TInfoLevel_Manager extends BaseAction
{

    public TInfoLevel_Manager()
    {
    }

    public String doList(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws Exception
    {
        String pagenos = request.getParameter("pageno");
        String pagesizes = request.getParameter("pagesize");
        try
        {
            pageno = Integer.valueOf(pagenos);
        }
        catch(NumberFormatException e)
        {
            pageno = new Integer(1);
        }
        if(pagesizes != null)
            pagesize = Integer.valueOf(pagesizes.trim());
        TInfoLevel_QueryMap query_map = new TInfoLevel_QueryMap();
        query_map.pageno = pageno;
        query_map.pagesize = pagesize;
        java.util.Iterator sl = null;
        if(sql_string == null || sql_string.equals("") || sql_string.equalsIgnoreCase("null"))
        {
            sl = query_map.findAll().iterator();
        } else
        {
            sl = query_map.findAll(sql_string, sql_param);
            request.setAttribute("sql_string", sql_string);
            request.setAttribute("sql_param", sql_param_str);
        }
        request.setAttribute("sl", sl);
        request.setAttribute("curpageno", pageno);
        if(pageno.intValue() > 1)
            request.setAttribute("prepage", new Integer(pageno.intValue() - 1));
        else
            request.setAttribute("prepage", new Integer(1));
        int totalpage = 0;
        if(query_map.totalrow % pagesize.intValue() == 0)
            totalpage = query_map.totalrow / pagesize.intValue();
        else
            totalpage = query_map.totalrow / pagesize.intValue() + 1;
        request.setAttribute("totalpage", new Integer(totalpage));
        if(pageno.intValue() < totalpage)
            request.setAttribute("nextpage", new Integer(pageno.intValue() + 1));
        else
            request.setAttribute("nextpage", new Integer(totalpage));
        return "list";
    }

    public String doDetail(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws Exception
    {
        try
        {
            request.setAttribute("sql_string", sql_string);
            request.setAttribute("sql_param", sql_param_str);
            String pageno = request.getParameter("pageno");
            request.setAttribute("pageno", pageno);
        }
        catch(RuntimeException e1)
        {
            e1.printStackTrace();
        }
        TInfoLevel_QueryMap sqm = new TInfoLevel_QueryMap();
        String uid = request.getParameter("id");
        TInfoLevel_Form sf = null;
        sf = sqm.getByID(uid);
        request.setAttribute("TInfoLevel_Form", sf);
        return "detail";
    }

    public String doCreate(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
    {
        try
        {
            request.setAttribute("sql_string", sql_string);
            request.setAttribute("sql_param", sql_param_str);
            String pageno = request.getParameter("pageno");
            request.setAttribute("pageno", pageno);
        }
        catch(RuntimeException e1)
        {
            e1.printStackTrace();
        }
                              
        request.setAttribute("TInfolevel_Form", new TInfoLevel_Form());
        return "addpage";
    }

    public String doAdd(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws Exception
    {
        TInfoLevel_EditMap editMap = new TInfoLevel_EditMap();
        try
        {
            TInfoLevel_Form vo = null;
            vo = (TInfoLevel_Form)form;
            if(null==vo.getTypeId())
            {
            	vo.setTypeIds(request.getParameterValues("typeId"));
            }
            editMap.add(vo);
        }
        catch(HibernateException e)
        {
            ActionErrors errors = new ActionErrors();
            errors.add("org.apache.struts.action.GLOBAL_ERROR", new ActionError("error.database.save", e.toString()));
            saveErrors(request, errors);
            e.printStackTrace();
            request.setAttribute("TInfoType_Form", form);
            return "addpage";
        }
        return "aftersave";
    }

    public String doQuery(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
    {
        try
        {
            String pageno = request.getParameter("pageno");
            request.setAttribute("pageno", pageno);
        }
        catch(RuntimeException e1)
        {
            e1.printStackTrace();
        }
        return "searchpage";
    }

    public String doEdit(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws Exception
    {
        try
        {
            request.setAttribute("sql_string", sql_string);
            request.setAttribute("sql_param", sql_param_str);
            String pageno = request.getParameter("pageno");
            request.setAttribute("pageno", pageno);
        }
        catch(RuntimeException e1)
        {
            e1.printStackTrace();
        }
        TInfoLevel_QueryMap query_map = new TInfoLevel_QueryMap();
        String uid = request.getParameter("id");
        TInfoLevel_Form vo = null;
        query_map.session.flush();
        vo = query_map.getByID(uid);
        request.setAttribute("TInfoLevel_Form", vo);
        return "editpage";
    }

    public String doUpdate(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws Exception
    {
        try
        {
            TInfoLevel_EditMap edit_map = new TInfoLevel_EditMap();
            TInfoLevel_Form vo = null;
            vo = (TInfoLevel_Form)form;
            if(null==vo.getTypeId())
            {
            	vo.setTypeIds(request.getParameterValues("typeId"));
            }
            //System.out.println("vo.getFunctionid()="+vo.getFunctionid());
            edit_map.update(vo);
        }
        catch(HibernateException e)
        {
            ActionErrors errors = new ActionErrors();
            errors.add("org.apache.struts.action.GLOBAL_ERROR", new ActionError("error.database.save", e.toString()));
            saveErrors(request, errors);
            e.printStackTrace();
            request.setAttribute("TInfoType_Form", form);
            return "editpage";
        }
        return "aftersave";
    }

    public String doDelete(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws Exception
    {
        TInfoLevel_EditMap edit_map = new TInfoLevel_EditMap();
        String uid = request.getParameter("id");
        try
        {
            edit_map.delete(uid);
        }
        catch(HibernateException e)
        {
            ActionErrors errors = new ActionErrors();
            errors.add("org.apache.struts.action.GLOBAL_ERROR", new ActionError("error.database.save", e.toString()));
            saveErrors(request, errors);
            e.printStackTrace();
            return "list";
        }
        return "aftersave";
    }
}